# Contributor: Taner Tas <taner76@gmail.com>
# Maintainer: Taner Tas <taner76@gmail.com>
pkgname=freeimage
_pkgname="FreeImage"
pkgver=3.18.0
pkgrel=2
pkgdesc="Open Source library project for developers who would like to support popular graphics image formats."
url="http://freeimage.sourceforge.net/"
arch="all !s390x" # build fails on s390x
license="GPL-2.0-or-later FIPL"
makedepends="dos2unix"
subpackages="$pkgname-dev"
source="https://downloads.sourceforge.net/$pkgname/${_pkgname}${pkgver//.}.zip
	0001-no-root-install.patch
	0002-fix-cpuid-x86.patch
	0005-makefile-gnu.patch
	CVE-2019-12211_3.patch
	fix-build.patch
	"

options="!check"

# secfixes:
#   3.18.0-r2:
#     - CVE-2019-12211
#     - CVE-2019-12213

prepare() {
	mv $srcdir/$_pkgname $srcdir/$pkgname-$pkgver
	find "$builddir" -type f -exec dos2unix -q -s {} \;
	default_prepare
}

build() {
	case "$CARCH" in
		aarch64) export CFLAGS="$CFLAGS -DPNG_ARM_NEON_OPT=0";;
		ppc64le) export CFLAGS="$CFLAGS -U__ALTIVEC__";;
	esac
	make
}

package() {
	make DESTDIR="$pkgdir" install
}
sha512sums="
9d9cc7e2d57552c3115e277aeb036e0455204d389026b17a3f513da5be1fd595421655488bb1ec2f76faebed66049119ca55e26e2a6d37024b3fb7ef36ad4818  FreeImage3180.zip
2dc51d700671962339cc1f27c0ad7e679e7ed6233d1534b81d68fcffb6e86960fa182b6916d19da7451bf34b69efe4a1b62b7f335b9802d7799706b766257d59  0001-no-root-install.patch
ef88862593bd8d271d11f86ec389c8a92c131ffb03fb7028e87dfddc7ae74e22bef50327175a7dcee9c414df80e84579c59f3b8e1f825d54f0fdc76a0530c06f  0002-fix-cpuid-x86.patch
18fba0dc68f94365ffbe7070594825b7e8f77f462ece31d96971de18f085b5110f3c3bdff780a02aa162ee9a64dd20c5fda7871d8759c8eeaa20d7bf3dddd72e  0005-makefile-gnu.patch
de88bbf9f5d43f2b5be4d4df3baabb895ba6dca1d28308909f825f973634bdf8bc10bda61b2ce90e48f67d024cf6ab75f797ce42474101fa6a0896ee42107770  CVE-2019-12211_3.patch
e3d2897c70121a67c93ceb941729a7238a1bed3b016492927d6e92c53ae8685a099787323111978be6db7c009249608ac625fff0d07f27e193d0c06eaf646058  fix-build.patch
"
